extends NinePatchRect

onready var al = $a
onready var dl = $d
onready var hl = $h

var a = 0.0
var d = 0.0
var h = 0.0
var w = 0.0

#承伤详情
var hurtData = {}
#技能伤害详情
var dmgData = {}

var cha = null
var utils = null
func _ready():
	utils = sys.get_node("VEBase").utils

func init(cha:Chara):
	cha.connect("onCastHurt",self,"onCastHurt")
	cha.connect("onHurt",self,"onHurt")
	cha.connect("onCastPlus",self,"onCastPlus")
	self.cha = cha
	$name.text = cha.name
	$name.set("custom_colors/font_color",Color(cons.colorDs.lvs[cha.lv-1]))
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
#	pass
func onCastHurt(atkInfo):
	preHandleAtkInfo(atkInfo)
	a += atkInfo.finalVal
	utils.dicPlus(dmgData, atkInfo.name, atkInfo.finalVal)
	
func onHurt(atkInfo):
	preHandleAtkInfo(atkInfo)
	d += atkInfo.finalVal
	utils.dicPlus(hurtData, atkInfo.castCha.name, atkInfo.finalVal)
	
func onCastPlus(info):
	if info.type == "hp" :
		h += info.finalVal
	elif info.type == "ward" :
		w += info.finalVal

func preHandleAtkInfo(atkInfo):
	if atkInfo.source == null or atkInfo.source is Chara or atkInfo.source is String or atkInfo.source.get("name") == null:
		if atkInfo.atkType == cha.ATKTYPE.NORMAL and atkInfo.hurtType == cha.HURTTYPE.PHY:
			atkInfo["name"] = "普攻"
		else:
			atkInfo["name"] = "其他"
	else:
		atkInfo["name"] = atkInfo.source.get("name")


func _on_Button_pressed():
	var dlg = sys.newDlg("res://tscn/bat/hurt/hurtDetailDlg.tscn")
	dlg.init(self)
	#sys.newDlg("res://tscn/tile/selModeDlg.tscn")

func up():
	al.text = "%d" % a
	dl.text = "%d" % d
	hl.text = "%d/%d" % [h,w]
